package cn.wizzer.app.web.commons.ext.websocket.filter;

import cn.wizzer.app.user.modules.models.vo.ChatUserVO;
import cn.wizzer.app.user.modules.services.UserService;
import cn.wizzer.app.web.commons.ext.websocket.main.action.BaseNettyAction;
import cn.wizzer.app.web.commons.ext.websocket.main.base.NettyCache;
import cn.wizzer.app.web.commons.ext.websocket.main.base.NettyRouter;
import cn.wizzer.app.web.commons.ext.websocket.main.filter.BaseNettyFilter;
import cn.wizzer.app.web.commons.ext.websocket.main.filter.NettyFilter;
import cn.wizzer.app.web.commons.utils.TokenUtilImpl;
import cn.wizzer.framework.base.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

/**
 * 登录认证
 */
//支持集成|spring.@Baen
@IocBean
@NettyFilter
public class AttendantFilter extends BaseNettyFilter {
    @Inject
    private TokenUtilImpl tokenUtil;

    @Inject
    @Reference
    private UserService userService;

    @Override
    public Result doFilter(NettyRouter router, BaseNettyAction action) {
        String appid = router.getParam("appid").toString();

        ChatUserVO chatUserVO = NettyCache.globalGet(appid);
        if (chatUserVO.isAttendant()) {
            return null;
        }
        return Result.error("非客服人员无法访问");
    }
}
